import cv2

if __name__ == '__main__':
    # 打开视频文件
    vc = cv2.VideoCapture('./images/1.mp4')
    # 打开摄像头
    # vc cv2.VideoCapture(0)

    cv2.namedWindow("window", cv2.WINDOW_NORMAL)

    # 视频的本质上就是由一张一张图片组成的
    count = 1
    while vc.isOpened():   # vc.isOpened()  视频文件或摄像头是否正常打开
        # 读取视频的每一帧,返回标记和这一帧数据
        status, frame = vc.read()
        if status:
            cv2.imshow('window', frame)
            cv2.waitKey(1000//30)  # 等待50毫秒

            # 保存视频帧
            # cv2.imwrite(f'images/videoFrame/{count}.jpg', frame)
            # count += 1
        else:
            # 释放资源
            vc.release()
            # 销毁所有窗口
            cv2.destroyAllWindows()
            break
